package com.mall.service.impl;

import com.mall.beans.ShoppingCart;
import com.mall.mapper.ShoppingCartMapper;
import com.mall.service.ShoppingCartService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 购物车表(ShoppingCart)表服务实现类
 *
 * @author 周彭
 * @since 2020-12-22 09:33:56
 */
@Service("shoppingCartService")
public class ShoppingCartServiceImpl implements ShoppingCartService {
    @Resource
    private ShoppingCartMapper shoppingCartMapper;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public ShoppingCart queryById(Integer id) {
        return this.shoppingCartMapper.queryById(id);
    }

    /**
     * 查询所有
     *
     * @return 实例对象
     */
    @Override
    public List<ShoppingCart> all() {
        return this.shoppingCartMapper.all();
    }

    /**
     * 查询多条数据
     *
     * @param offset 查询起始位置
     * @param limit  查询条数
     * @return 对象列表
     */
    @Override
    public List<ShoppingCart> queryAllByLimit(int offset, int limit) {
        return this.shoppingCartMapper.queryAllByLimit(offset, limit);
    }

    /**
     * 新增数据
     *
     * @param shoppingCart 实例对象
     * @return 实例对象
     */
    @Override
    public ShoppingCart insert(ShoppingCart shoppingCart) {
        this.shoppingCartMapper.insert(shoppingCart);
        return shoppingCart;
    }

    /**
     * 修改数据
     *
     * @param shoppingCart 实例对象
     * @return 实例对象
     */
    @Override
    public ShoppingCart update(ShoppingCart shoppingCart) {
        this.shoppingCartMapper.update(shoppingCart);
        return this.queryById(shoppingCart.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer id) {
        return this.shoppingCartMapper.deleteById(id) > 0;
    }
}